<?php


	namespace app\controller\shop;


	use app\lib\interfaces\eventInterfaces;

	class Index implements eventInterfaces
	{


		public function index () {
			// TODO: Implement index() method.
		}


		public function say ($id) {
			// TODO: Implement say() method.
		}


		public function pull () {
			$body = json_decode(file_get_contents("php://input"), true);
			if(empty($body)){
				Log::error("WebHooks data null");
				die('data null!');
			}
			// 请求密码
			$password = '123456';
			if($password != $body['password']){
				die('WebHooks password error!');
			}
			if (isset($body['ref'])) {
				// 验证提交分支是否为master
				if ($body['ref'] == 'refs/heads/master') {
					$command = " cd /home/yir  && sudo sh ./yr.luyir.sh";
				} else if ($body['ref'] == 'refs/heads/dev') {// 验证提交分支是否为dev
					$command = " cd /home/yir  && sudo  sh ./yr.test.luyir.sh";
				} else{
					die('WebHooks the main branch');
				}
			} else {
				die('WebHooks ref null');
			}

			$res = shell_exec($command);
			Log::info('res='.print_r($res,true));
			die('done');
		}
	}




	